/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.openbrew.openbrewrf;

import java.io.Serializable;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author chapmand
 */
@Entity
@Table(name = "Beer")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Beer.findAll", query = "SELECT b FROM Beer b ORDER BY b.bName ASC"),
    @NamedQuery(name = "Beer.findByBId", query = "SELECT b FROM Beer b WHERE b.bId = :bId"),
    @NamedQuery(name = "Beer.findByBName", query = "SELECT b FROM Beer b WHERE b.bName = :bName"),
    @NamedQuery(name = "Beer.findByBAbv", query = "SELECT b FROM Beer b WHERE b.bAbv = :bAbv"),
    @NamedQuery(name = "Beer.findByBIbu", query = "SELECT b FROM Beer b WHERE b.bIbu = :bIbu"),
    @NamedQuery(name = "Beer.findByBSrm", query = "SELECT b FROM Beer b WHERE b.bSrm = :bSrm"),
    @NamedQuery(name = "Beer.findByBNotes", query = "SELECT b FROM Beer b WHERE b.bNotes = :bNotes"),
    @NamedQuery(name = "Beer.findByInProduction", query = "SELECT b FROM Beer b WHERE b.inProduction = :inProduction"),
    @NamedQuery(name = "Beer.findByBeerFermDays", query = "SELECT b FROM Beer b WHERE b.beerFermDays = :beerFermDays"),
    @NamedQuery(name = "Beer.findByBeerSecondDays", query = "SELECT b FROM Beer b WHERE b.beerSecondDays = :beerSecondDays"),
    @NamedQuery(name = "Beer.findByBeerCondDays", query = "SELECT b FROM Beer b WHERE b.beerCondDays = :beerCondDays"),
    @NamedQuery(name = "Beer.findByBeerFilter", query = "SELECT b FROM Beer b WHERE b.beerFilter = :beerFilter"),
    @NamedQuery(name = "Beer.findByBeerFine", query = "SELECT b FROM Beer b WHERE b.beerFine = :beerFine"),
    @NamedQuery(name = "Beer.findByBCOVols", query = "SELECT b FROM Beer b WHERE b.bCOVols = :bCOVols"),
    @NamedQuery(name = "Beer.findAllInProduction", query = "SELECT b FROM Beer b WHERE b.inProduction = true ORDER BY b.bName ASC")})
public class Beer implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "BId")
    private Integer bId;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 40)
    @Column(name = "BName")
    private String bName;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BAbv")
    private float bAbv;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BIbu")
    private float bIbu;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BSrm")
    private float bSrm;
    @Basic(optional = false)
    @NotNull
    @Size(min = 0, max = 100)
    @Column(name = "BNotes")
    private String bNotes;
    @Basic(optional = false)
    @NotNull
    @Column(name = "InProduction")
    private boolean inProduction;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BeerFermDays")
    private int beerFermDays;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BeerSecondDays")
    private int beerSecondDays;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BeerCondDays")
    private int beerCondDays;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BeerFilter")
    private boolean beerFilter;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BeerFine")
    private boolean beerFine;
    @Basic(optional = false)
    @NotNull
    @Column(name = "BCOVols")
    private float bCOVols;
    @JoinColumn(name = "RecipeID", referencedColumnName = "RID", nullable=true)
    @ManyToOne(optional = true)
    private Recipes recipeID;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "bBeerID")
    private Collection<Brews> brewsCollection;
    @JoinColumn(name = "BCost", referencedColumnName = "CostID", nullable=true)
    @ManyToOne(optional = true)
    private Cost bCost;
    @OneToMany(cascade=CascadeType.REFRESH, fetch=FetchType.EAGER)
    @JoinTable(
        name="JTBeerToDoc",
        joinColumns={ @JoinColumn(name="beerID", referencedColumnName="BId")},
        inverseJoinColumns={ @JoinColumn(name="docID", referencedColumnName="docID", unique=true)}
    )
    private List<Documents> docCollection;

    public Beer() {
    }

    public Beer(Integer bId) {
        this.bId = bId;
    }

    public Beer(Integer bId, String bName, float bAbv, float bIbu, int bSrm, String bNotes, boolean inProduction, int beerFermDays, int beerSecondDays, int beerCondDays, boolean beerFilter, boolean beerFine, float bCOVols) {
        this.bId = bId;
        this.bName = bName;
        this.bAbv = bAbv;
        this.bIbu = bIbu;
        this.bSrm = bSrm;
        this.bNotes = bNotes;
        this.inProduction = inProduction;
        this.beerFermDays = beerFermDays;
        this.beerSecondDays = beerSecondDays;
        this.beerCondDays = beerCondDays;
        this.beerFilter = beerFilter;
        this.beerFine = beerFine;
        this.bCOVols = bCOVols;
    }

    public Integer getBId() {
        return bId;
    }

    public void setBId(Integer bId) {
        this.bId = bId;
    }

    public String getBName() {
        return bName;
    }

    public void setBName(String bName) {
        this.bName = bName;
    }

    public float getBAbv() {
        return bAbv;
    }

    public void setBAbv(float bAbv) {
        this.bAbv = bAbv;
    }

    public float getBIbu() {
        return bIbu;
    }

    public void setBIbu(float bIbu) {
        this.bIbu = bIbu;
    }

    public float getBSrm() {
        return bSrm;
    }

    public void setBSrm(float bSrm) {
        this.bSrm = bSrm;
    }

    public String getBNotes() {
        return bNotes;
    }

    public void setBNotes(String bNotes) {
        this.bNotes = bNotes;
    }

    public Cost getBCost() {
        return bCost;
    }

    public void setBCost(Cost bCost) {
        if(bCost != null && bCost.getCostID() != null){
            this.bCost = bCost;
        }
    }

    public Recipes getRecipeID() {
        return recipeID;
    }

    public void setRecipeID(Recipes recipeID) {
        if(recipeID != null && recipeID.getRid() != null){
            this.recipeID = recipeID;
        }
    }

    public boolean getInProduction() {
        return inProduction;
    }

    public void setInProduction(boolean inProduction) {
        this.inProduction = inProduction;
    }

    public int getBeerFermDays() {
        return beerFermDays;
    }

    public void setBeerFermDays(int beerFermDays) {
        this.beerFermDays = beerFermDays;
    }

    public int getBeerSecondDays() {
        return beerSecondDays;
    }

    public void setBeerSecondDays(int beerSecondDays) {
        this.beerSecondDays = beerSecondDays;
    }

    public int getBeerCondDays() {
        return beerCondDays;
    }

    public void setBeerCondDays(int beerCondDays) {
        this.beerCondDays = beerCondDays;
    }

    public boolean getBeerFilter() {
        return beerFilter;
    }

    public void setBeerFilter(boolean beerFilter) {
        this.beerFilter = beerFilter;
    }

    public boolean getBeerFine() {
        return beerFine;
    }

    public void setBeerFine(boolean beerFine) {
        this.beerFine = beerFine;
    }

    public float getBCOVols() {
        return bCOVols;
    }

    public void setBCOVols(float bCOVols) {
        this.bCOVols = bCOVols;
    }

    @XmlTransient
    public Collection<Brews> getBrewsCollection() {
        return brewsCollection;
    }

    public void setBrewsCollection(Collection<Brews> brewsCollection) {
        this.brewsCollection = brewsCollection;
    }

    public List<Documents> getDocumentsCollection() {
        return docCollection;
    }

    public void setDocumentsCollection(List<Documents> docCollection) {
        this.docCollection = docCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (bId != null ? bId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Beer)) {
            return false;
        }
        Beer other = (Beer) object;
        if ((this.bId == null && other.bId != null) || (this.bId != null && !this.bId.equals(other.bId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.openbrew.openbrewrf.Beer[ bId=" + bId + " ]";
    }
    
}
